package Event;

import Creature.Player;
import Event.daliy.*;
import Event.lib.*;
import Event.mainLine.mainLine0;
import Event.mainLine.*;
import acm.util.RandomGenerator;

import java.util.ArrayList;

public class EventLine {
    Story[] eventList;
    ArrayList<Story> canHappenList;
    MainStory[] keyEventList;
    Story[] daily1Event;
    Story[] daily2Event;
    RandomGenerator randomGenerator = RandomGenerator.getInstance();
    Player player;
    public int keyEventIndex;

    public EventLine(Player player){
        this.player=player;
        eventList= new Story[]{new EncounterDriver(player),new Foodinsert(player),new GarbageCollection(player),
                new HelpOldman(player),new Lottery(player),new Packageupgrade(player),new Shop(player),new SmokeInLiarary(player),
                new Sour(player),new spoilTakeout(player),new StealTakeOut(player),new Supermarket(player)};
        daily1Event=new Story[]{new Dailyevent1(player)};
        daily2Event=new Story[]{new Dailyevent2(player)};
        keyEventList=new MainStory[]{new mainLine0(player),new mainLine1(player),new mainLine2(player),new mainLine3(player),new mainLine4(player)
        ,new mainLine5(player),new mainLine6(player),new mainLine7(player),new mainLine8(player),new mainLine9(player),new mainLine10(player),
                new mainLine11(player),new mainLine12(player),new End1(player),new End2(player),new End3(player),new End4(player),new EndNormal(player),new EndDeath(player)};
        canHappenList=new ArrayList<>();
    }
    public Story pushEvent(int Days){
        makeCanHappenList();
        if(isKeyDay(Days)){
            MainStory event= keyEventList[keyEventIndex];
            return event;
        }else {
            return canHappenList.get(randomGenerator.nextInt(0,canHappenList.size()-1));
        }
    }

    public Story pushDailyEvent1(){
        return daily1Event[randomGenerator.nextInt(0,daily1Event.length-1)];
    }

    public Story pushDailyEvent2(){
        return daily2Event[randomGenerator.nextInt(0,daily2Event.length-1)];

    }

    public boolean isKeyDay(int Days){
        switch (Days){
            case 1:
            case 3:
            case 5:
            case 7:
            case 9:
            case 11:
            case 12:
            case 13:
            case 14:
                return true;
            default:
                return false;
        }

    }

    public void makeCanHappenList(){
        try {
            canHappenList.clear();
        } catch (Exception e) {
            e.printStackTrace();
        }
        for (Story e:eventList) {
            if(e.canHappen(player)){
                canHappenList.add(e);
            }
        }
    }
}

